Find Factors of a Number using While Loop with validation

42

print("Enter a Number: ", end="")
try:
    num = int(input())

    print("\nFactors of " +str(num)+ " are: ", end="")
    i = 1
    while i<=num:
        if num % i == 0:
            print(i, end=" ")
        i = i + 1
    print()
except ValueError:
    print("\nInvalid Input!")

Comments

Submit
0 Comments